package com.qf.agro.web.controller.sys;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.ResultInfo;
import com.qf.agro.pojo.sys.Company;
import com.qf.agro.pojo.sys.SysUser;
import com.qf.agro.service.sys.CompanyService;
import com.qf.agro.vo.OptionVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @company：千锋教育
 * @author：zhy
 * @date：2023/6/29
 * 企业的表现层对象
 */
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    /**
     * 分页查询企业列表
     * @return
     */
    @ApiOperation("分页查询企业列表")
    @GetMapping(value = "/page",name = "分页查询企业列表")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String name){
        //1.调用业务层查询
        Page<Company> page = companyService.findPage(pageNum, pageSize, name);
        //2.返回
        return ResultInfo.success(page);
    }

    @GetMapping("/selectOptions")
    public ResultInfo selectOptions(){
        //调用业务层查询
        List<OptionVo> options = companyService.findOptions();
        //返回
        return ResultInfo.success(options);
    }

    /**
     * 企业新增
     * @param company
     * @return
     */
    @PostMapping
    public ResultInfo save(@RequestBody Company company){
        //1.调用业务层新增
        companyService.save(company);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 禁用企业
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        //1.调用业务层停用
        companyService.updateState(id);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 更新企业
     * @param company
     * @return
     */
    @PutMapping
    public ResultInfo update(@RequestBody Company company){
        //1.调用业务层更新
        companyService.update(company);
        //2.返回
        return ResultInfo.success(null);
    }

}
